// https://leetcode.cn/problems/license-key-formatting/
// Created by ade on 2022/8/8.
//
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

class Solution {
public:
    string licenseKeyFormatting(string s, int k) {
        int len = s.size();
        string tmp = "";
        string res = "";
        for (int i = len - 1; i >= 0; i--) {
            if (s[i] == '-') continue;
            if (s[i] >= 'a' && s[i] <= 'z') tmp += toupper(s[i]);
            else tmp += s[i];

            if (tmp.size() == k) {
                res += tmp + "-";
                tmp = "";
            }
        }
        if (tmp != "") {
            res += tmp;
        } else {
            res = res.substr(0, res.size() - 1);
        }
        reverse(res.begin(), res.end());
        return res;
    }
};

int main() {

    cout<<toupper("2e9w");
    return 0;
    Solution so;
    string s = "5F3Z-2e-9-w";
    int k = 4;
    cout << so.licenseKeyFormatting(s, k) << endl;
    return 0;
}